#include <windows.h>
#include <iostream.h>

void main()
{
	CoInitialize(NULL);

	CLSID clsid;
	OLECHAR wb[] = L"Word.Application";
	CLSIDFromProgID(wb, &clsid);

	OLECHAR pszCLSID[39];
	StringFromGUID2(clsid, pszCLSID, 39);
	
	char buffer[39];
	wsprintf(buffer, "%S", pszCLSID);
	cout << "CLSID: " << buffer << endl;

	IDispatch* pDispatch;
	CoCreateInstance(clsid, NULL, CLSCTX_SERVER, IID_IDispatch, (void**)&pDispatch);

	DISPID dispid;
	OLECHAR* szMember = L"Visible";

	HRESULT hr = pDispatch->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
	if(FAILED(hr))
		cout << "GetIDsOfNames failed" << endl;
	cout << "DispID of Visible = " << dispid << endl;

	VARIANTARG test = { VT_BOOL, 0, 0, 0, VARIANT_TRUE };
	DISPID dispidnamed = DISPID_PROPERTYPUT;
	DISPPARAMS param = { &test, &dispidnamed, 1, 1 };

	hr = pDispatch->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
		DISPATCH_PROPERTYPUT, &param, NULL, NULL, NULL);
	if(FAILED(hr))
		cout << "Invoke failed" << endl;

	pDispatch->Release();
	CoUninitialize();
}